package com.crm.jdy.controller.usermanager;

import com.crm.jdy.common.dto.CallAplanInfoDto;
import com.crm.jdy.common.dto.RoleInfoDto;
import com.crm.jdy.common.pojo.CallAplanInfo;
import com.crm.jdy.common.pojo.RoleInfo;
import com.crm.jdy.common.utils.api.ResultVo;
import com.crm.jdy.common.utils.currentlimiting.RateLimit;
import com.crm.jdy.service.client.CallAplanInfoService;
import com.crm.jdy.service.usermanager.RoleInfoService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;

import javax.validation.constraints.NotNull;

/**
*
* <p>说明： 角色管理API接口层</P>
* @version: V1.0
* @author: kong
* @time    2021年3月30日
*
*/
@Validated
@Api(tags = "roleInfo", description = "角色管理")
@RestController
@RequestMapping("/roleInfo")
public class RoleInfoController{

    @Reference(version = "${service.version}", check = false)
    RoleInfoService callAplanInfoService;

    @RateLimit()
    @ApiOperation("角色管理信息")
    @PostMapping("/seleteRoleInfo")
    public ResultVo seleteRoleInfo(@RequestBody RoleInfoDto callAplanInfoDto){
        PageInfo<RoleInfo> list = callAplanInfoService.seleteRoleInfo(callAplanInfoDto);
        return  ResultVo.success(list);
    }

    @RateLimit()
    @ApiOperation("更新角色管理")
    @PostMapping("/updateRoleInfo")
    public ResultVo updateRoleInfo(@ApiParam(value = "roleInfo", required = true)
                                   @Validated @RequestBody RoleInfo roleInfo){
        boolean index = callAplanInfoService.updateRoleInfo(roleInfo);
        if(index){
            return  ResultVo.success();
        }
        return  ResultVo.failed();
    }

    @RateLimit()
    @ApiOperation("添加角色管理")
    @PostMapping("/addRoleInfo")
    public ResultVo addRoleInfo(@ApiParam(name = "roleInfo", required = false)
                                @Validated @RequestBody RoleInfo roleInfo){
        boolean list  = callAplanInfoService.addRoleInfo(roleInfo);
        if(list){
            return ResultVo.success("添加成功");
        }
        return ResultVo.failed("添加失败，数据已存在");
    }

    @RateLimit()
    @ApiOperation("删除角色管理")
    @DeleteMapping("deleteRoleInfo/{aplanId}")
    public ResultVo deleteRoleInfo(@NotNull @ApiParam(name = "aplanId", value = "aplanId", required = true) @PathVariable String aplanId){
        boolean b = callAplanInfoService.removeRoleInfo(aplanId);
        if(b){
            return ResultVo.success();
        }
        return ResultVo.failed();
    }

}